import {observable, action, toJS} from 'mobx';
import {message, Modal} from 'antd';
import * as api from '../../apis/plan/planReportViewApi';
import {WeaTableNew} from 'comsMobx';
import {WeaDatePicker, WeaInput, WeaTextarea, WeaInputNumber,WeaLocaleProvider} from 'ecCom';
const getLabel = WeaLocaleProvider.getLabel;
const getUserLanguage= WeaLocaleProvider.getUserLanguage;
import * as Util from '../../util/Util';
// import ThisMonthWorkSummary from 'pc4mobx/workrelate/components/plan/planReportView/ThisMonthWorkSummary';

const {TableStore} = WeaTableNew;
const confirm = Modal.confirm;

export default class PlanReportViewStore {
  //带observable 的会重新渲染

  @observable hasData = false;
  @observable uploading = false;
  @observable logLoading = false;
  @observable loading = false; // 页面初始化的loading状态：数据加载成功前后前使用
  @observable fileComLoading = false;
  @observable tableStore = new TableStore (); // new table

  @observable tabSelectKey = '1';
  @observable tabDatas = []; //顶部tabdatas

  @observable planSummaryModal = {
    planSummaryModalVisible: false,
    title: '总结',
    type: 'summary',
    edit: false,
    editData: '', //点击行编辑当前行内容
    rowIndex:-1
  };

  //type1 ：周报还是月报  type2 ：周或月的值
  @observable type1 = '';
  @observable type2 = '';
  //leftcom 改变的值
  @observable resourceid = '';
  @observable resourcetype = '';

  @observable dateSelect = {
    year: '',
    month: '',
    week: '',
  };

  @observable summaryColumns = [];
  @observable summaryinColumns = [];
  @observable planColumns = [];

  @observable yearDatas = [];
  //没数据的时候显示
  @observable noDataMessage = '';

  //权限 例如是否有编辑等的权限
  @observable authority = {
    canaudit: false,
    candel: false,
    canedit: false,
    canreset: false,
    canshare: false,
  };

  //按钮权限
  @observable buttonAuth = {
    edit: false,
    del: false,
    reset: false,
    audit: false,
    share: false,
  };

  //请求回来的计划详情数据 不做改动
  @observable requestRes = {};

  //请求回来的数据转存到这里
  @observable resData = {
    ismonth: '',
    isweek: '',
    planid: '',
    enddate: '',
    planstatus: '',
    planstatusname: '',
    resourcename: '',
    resourceid: '',
    currentmonth: '',
    summaryin: [],
    summaryout: [],
    planlist: [],
    fblist: [],
    shareIds: '',
    shareidsList: [],
    category: '',
    fileids: '',
    filearry: [],
  };

  //操作日志
  @observable planLog = {
    datas: [],
    lastcount: 0,
    lastid: '',
    status: '',
  };

  //详情
  @observable detailView = {
    id: '',
  };

  //操作日志请求参数
  planLogParam = {
    lastcount: 0,
    lastid: 1,
    planid: '',
    status: '',
  };

  //上传文件更改标识
  @observable uploadReset = true;

  @observable inputValue = {
    richTextValue: '',
    feedback: '',
  };

  //月份选择组件变化标识
  @observable locationkey = new Date ().getTime ();
  @observable monthWeekSelectComDisplayKey = '';

  msg = '';


  @action ('参数改变事件')
  onInputValueChange = (param, v) => {
    this.inputValue[param] = v;
  };

  @action ('看文档')
  viewDocFiled = params => {
    api.viewDocFiled (params).then (
      action (data => {
        if (data.api_status == '1') {
          params.doback ();
        }
      })
    );
  };

  @action ('设置按钮权限')
  setButtonAuth = () => {
    let {canaudit, canedit, candel, canreset, canshare} = this.authority;
    if (this.noDataMessage != '') {
      this.buttonAuth.edit = false;
      this.buttonAuth.reset = false;
      this.buttonAuth.audit = false;
      this.buttonAuth.del = false;
      this.buttonAuth.share = false;
      return;
    }
    this.buttonAuth = {
      edit: canedit,
      reset: canreset,
      share: canshare,
      audit: canaudit,
      del: candel,
    };
  };

  @action ('获取计划详情')
  getPlanDetail = params => {
    if (!params) {
      params = {};
      params.type1 = this.tabSelectKey == '1' ? '1' : '2';
      params.type2 = this.tabSelectKey == '1'
        ? this.dateSelect.month
        : this.dateSelect.week;
      params.year = this.dateSelect.year;
      params.resourceid = this.resourceid;
      params.resourcetype = this.resourcetype;
    }

    this.loading = true;
    this.fileComLoading = true
    this.hasData = false;
    api.getPlanDetail (params).then (action (res => {
          this.loading = false;
          this.fileComLoading =false
          if (res.api_status == 1) {
            this.setResData (res);
            this.summaryColumns = this.setColumns (res.summarymap);
            this.summaryinColumns = this.setSummaryInColumns (
              res.summarymap,
              res.planmap
            );
            this.planColumns = this.setColumns (res.planmap);
            this.requestRes = res;
            if (res && res.planid) {
              this.planLog = {
                datas: [],
                lastcount: 0,
                lastid: '',
                status: '',
                logType: 'noView',
              };
              this.getPlanLog ();
            }
            this.noDataMessage = '';
            this.locationkey = new Date ().getTime ();
            this.msg = '1';
          } else {
            this.setResData (res);
            this.resData.isweek = res.isweek;
            this.resData.ismonth = res.ismonth;
            this.noDataMessage = res.api_status;
            this.msg = '0';
          }
          //设置时间
          this.dateSelect.year = res.year;
          res.type1 == '1'
            ? (this.dateSelect.month = res.type2)
            : (this.dateSelect.week = res.type2);
          if(res.type1==1 && this.dateSelect.month>12){
            this.dateSelect.month = new Date().getMonth()+1
          }
          this.tabSelectKey=res.type1
          this.setButtonAuth ();
          this.setTabSelectKeyByTabDatas ();
          this.tabDatas = res.tabDatas;
          this.locationkey = new Date ().getTime ();
          this.hasData = true;
          this.loading = false;
          this.msg = '0';
        })
      )
      .catch (res => {
        this.hasData = true;
        this.loading = false;
        this.msg='0'
      });
  };

  @action ('获取请求日志')
  getPlanLog = () => {
    this.loading = true;
    this.planLog.planid = this.resData.planid;
    api.getPlanLog (this.planLog).then (
      action (res => {
        if (res.api_status == '1') {
          let tempArray = toJS (this.planLog.datas);
          tempArray.push (...res.datas);
          this.planLog = res;
          this.planLog.datas = tempArray;
        } else {
          message.error (res.message || '接口调用失败！');
        }

        this.loading = false;
      })
    ).catch (res => {
      this.loading = false;
    });
  };

  //planlist默认的计划如果没有id补上temp开头的id
  addPlanListDefaultId=(planlist)=>{
    return planlist.map(p=>{
      if(!p.id){
        p.id='temp'+Math.random()
      }
      return p
    })
  }

  @action ('接受参数以后，放到resData里，方便以后使用')
  setResData = res => {
    this.resData.ismonth = res.ismonth;
    this.resData.isweek = res.isweek;
    this.resData.planid = res.planid;
    this.resData.planname = res.planname;
    this.resData.auditids = res.auditids;
    this.resData.enddate = res.enddate;
    this.resData.planstatus = res.planstatus;
    this.setPlanStatusName (res.planstatus);
    this.resData.resourcename = res.resourcename;
    this.resData.resourceid = res.resourceid;
    this.resourceid = res.resourceid?res.resourceid:this.resourceid;
    this.resourcename = res.resourcename;
    this.resData.currentmonth = res.currentmonth;
    this.resData.remark = res.remark ? res.remark:'';
    this.inputValue.richTextValue= res.remark ? res.remark:'';
    this.resData.summaryin = res.summaryin ? res.summaryin : [];
    this.resData.summaryout = res.summaryout ? res.summaryout : [];
    this.resData.planlist = res.planlist ? this.addPlanListDefaultId(res.planlist) : [];
    this.resData.planmap = res.planmap ? res.planmap : [];
    this.resData.summarymap = res.summarymap ? res.summarymap : [];
    this.resData.fblist = res.fblist ? res.fblist : [];
    this.resData.programid = res.programid;
    this.resData.shareidsList = res.shareidsList || [];
    this.resData.category = res.category;
    this.resData.filearry = res.filearry ? res.filearry : [];
    this.resData.fileids = res.fileids ? res.fileids : '';
    this.resData.createtask = res.createtask;
    this.resData.maxsize = res.maxsize;
    this.resData.auditList=res.auditList
    this.resData.isperformance = res.isperformance
    this.resData.alinks=res.alinks?res.alinks:[]
    //设置时间信息
    this.dateSelect.year = res.year;
    res.type1 == '1'
      ? (this.dateSelect.month = res.type2)
      : (this.dateSelect.week = res.type2);

    //设置权限信息
    this.authority.canaudit = res.canaudit;
    this.authority.candel = res.candel;
    this.authority.canedit = res.canedit;
    this.authority.canreset = res.canreset;
    this.authority.canshare = res.editshare;
  };

  @action ('设置标签名')
  setPlanStatusName = status => {
    status = parseInt (status);
    switch (status) {
      case 0:
        this.resData.planstatusname = getLabel('509106','草 稿') ;
        break;
      case 1:
        this.resData.planstatusname = getLabel('19134','审批中') ;
        break;
      case 2:
        this.resData.planstatusname = getLabel('509108','退 回') ;
        break;
      case 3:
        this.resData.planstatusname = getLabel('23774','已完成') ;
        break;
      case 6:
        this.resData.planstatusname = getLabel('382750','已过期') ;
        break;
      default:
        break;
    }
  };

  //设置列元数据
  setColumns = columnMap => {
    const columnConfigs = columnMap.list;
    if (!columnConfigs || columnConfigs.length < 1) {
      return [];
    }
    let columns = [];
    let totalShowWidth = 0;
    columnConfigs.map (config => {
      totalShowWidth += parseInt (config.showwidth);
    });

    columnConfigs.map ((config, i) => {
      let width = parseInt (config.showwidth) / totalShowWidth * 100;
      columns.push ({
        title: config.showname,
        dataIndex: config.s_fieldname,
        key: config.s_fieldname,
        width: config.showwidth + '%',
        com: [
          {
            type: 'text', //timepicker inputnumber TEXTAREA text
            key: config.s_fieldname,
            hasHiddenField: true,
            defaultValue: '',
            viewAttr: 2,
          },
        ],
      });
    });
    return columns;
  };

  //下个月工作计划和本月的计划内比较，计划内没有的字段才可以编辑
  isSummaryInFieldCanEdit (fieldname, planMap) {
    let canEdit = true;
    planMap.list.map (p => {
      if (fieldname == p.fieldname) {
        canEdit = false;
      }
    });
    return canEdit;
  }

  //设置计划内元数据
  setSummaryInColumns = (columnMap, planMap,ecId) => {
    const columnConfigs = columnMap.list;
    if (!columnConfigs || columnConfigs.length < 1) {
      return [];
    }
    let columns = [];
    let totalShowWidth = 0;
    columnConfigs.map (config => {
      totalShowWidth += parseInt (config.showwidth);
    });
    let {summaryin} = this.resData;
    columnConfigs.map ((config, i) => {
      let width = parseInt (config.showwidth) / totalShowWidth * 100;
      //下个月工作计划和本月的计划内比较，计划内没有的字段才可以编辑
      let viewAuth = this.isSummaryInFieldCanEdit (config.fieldname, planMap) &&
      this.authority.canedit
      ? (config.ismust==1?3:2)
      : 1

      columns.push ({
        title: config.showname,
        dataIndex: config.fieldname,
        key: config.fieldname,
        width: config.showwidth + '%',
        render: (text, record, index) => {
          let type = this.getInputType (config.fieldname);
          let com;
          switch (type) {
            case 'datepicker':
              com = (
                <WeaDatePicker ecId={`${ecId}_WeaDatePicker@i3js8m@${index}`}
                  id={config.fieldname}
                  // width={width+"%"}
                  value={text}
                  viewAttr={
                    viewAuth
                  }
                  onChange={value => {
                    let preValue = JSON.parse (
                      JSON.stringify (summaryin[index][config.fieldname])
                    );
                    summaryin[index][config.fieldname] = value;
                    if (!this.checkDateIsValidata (summaryin[index])) {
                      summaryin[index][config.fieldname] = preValue;
                    }
                  }}
                />
              );
              break;
            case 'textarea':
              com = (
                <WeaTextarea ecId={`${ecId}_WeaTextarea@m7a2o3@${index}`}
                  id={config.fieldname}
                  // width={width+"%"}
                  value={text}
                  viewAttr={
                    viewAuth
                  }
                  onChange={value => {
                    summaryin[index][config.fieldname] = value;
                  }}
                />
              );
              break;
            case 'inputnumber':
              com = (
                <WeaInputNumber ecId={`${ecId}_WeaInputNumber@3szm8j@${index}`}
                  id={config.fieldname}
                  // width={width+"%"}
                  value={text}
                  viewAttr={
                    viewAuth
                  }
                  onChange={value => {
                    summaryin[index][config.fieldname] = value;
                  }}
                />
              );
              break;
            default:
              com = (
                <WeaInput ecId={`${ecId}_WeaInput@g1wlq2@${index}`}
                  id={config.fieldname}
                  // width={width+"%"}
                  value={text}
                  viewAttr={
                    viewAuth
                  }
                  onChange={value => {
                    summaryin[index][config.fieldname] = value;
                  }}
                />
              );
          }

          return com;
        },
      });
    });
    return columns;
  };

  //输入框类型判断
  getInputType (fieldname) {
    let datepickList = ['date'];
    let inputNumList = ['days1', 'days2', 'finishrate'];
    let textareaList = ['name', 'target', 'result', 'custom'];
    let datepickCheck = v => {
      let flag = false;
      datepickList.map (d => {
        if (v.indexOf (d) > -1) {
          flag = true;
        }
      });
      return flag;
    };

    if (datepickCheck (fieldname)) {
      return 'datepicker';
    } else if (inputNumList.indexOf (fieldname) > -1) {
      return 'inputnumber';
    } else if (textareaList.indexOf (fieldname) > -1) {
      return 'textarea';
    } else {
      return 'text';
    }
  }

  //检查日期
  checkDateIsValidata (d) {
    let days = 0;
    let flag = true;
    let col = '';
    let tip = '';
    if (d['begindate2'] && d['enddate2'] && d['enddate2'] != '') {
      days = Util.DateDiffDays (d['begindate2'], d['enddate2']);
      if (days < 0) {
        flag = false;
        tip = getLabel('509026','实际开始日期不能大于实际结束日期!') ;
      } else {
        col = 'days2';
      }
    } else if (d['enddate2'] && d['begindate2'] && d['begindate2'] != '') {
      days = Util.DateDiffDays (d['enddate2'], d['begindate2']);
      if (days < 0) {
        flag = false;
        tip = getLabel('509027','实际结束日期不能小于实际开始日期!') ;
      } else {
        col = 'days2';
      }
    } else if (d['begindate1'] && d['enddate1'] && d['enddate1'] != '') {
      days = Util.DateDiffDays (d['begindate1'], d['enddate1']);
      if (days < 0) {
        flag = false;
        tip = getLabel('509028','计划开始日期不能大于计划结束日期!') ;
      } else {
        col = 'days1';
      }
    } else if (d['enddate1'] && d['begindate1'] && d['begindate1'] != '') {
      days = Util.DateDiffDays (d['enddate1'], d['begindate1']);
      if (days < 0) {
        flag = false;
        tip = getLabel('509029','计划结束日期不能小于计划开始日期!') ;
      } else {
        col = 'days1';
      }
    }
    if (col != '' && days >= 0) {
      d[col] = days;
    }
    if (!flag) {
      message.info (tip);
    }
    col = '';

    return flag;
  }

  //返回comtype
  returnComtype (ele) {
    let comtype = '';
    switch (ele.inputtype) {
      case '1':
        comtype = 'INPUT';
        break;
      case '2':
        comtype = 'TEXTAREA';
        break;
      case '3':
        comtype = 'DATEPICKER';
        break;
      case '4':
        comtype = 'INPUTNUMBER';
        break;
      default:
        break;
    }

    return comtype;
  }

  //日期变动事件
  @action onDateChange = (param, v,isRefresh) => {
    this.dateSelect[param] = v;
    if(!isRefresh){
      this.getPlanDetail ();
    }
  };

  //获取年份选择框
  getYearSelectoption = () => {
    if (this.yearDatas.length < 1) {
      return this.initYearDateSelectOptions ();
    }
    return this.yearDatas;
  };

  //初始化年份选择框
  initYearDateSelectOptions = () => {
    let currentYear = parseInt (new Date ().getFullYear ());
    let yearList = [];
    for (var i = currentYear; i > currentYear - 6; i--) {
      yearList.push ({showname: i, key: i});
    }
    this.yearDatas = yearList;
  };

  doOperation = (operation,doback) => {
    switch (operation) {
      case 'save':
        this.saveOrSubmitPlan ('save');
        break;
      case 'del':
        this.deletePlan ();
        break;
      case 'submit':
        this.saveOrSubmitPlan ('submit');
        break;
      case 'reset':
        this.resetPlan ();
        break;
      case 'approve':
        this.auditPlan ('approve',doback);
        break;
      case 'return':
        this.auditPlan ('return',doback);
        break;
      case 'share':
      default:
        break;
    }
  };

  //审核计划
  auditPlan = (operation,doback) => {
    let params = {};
    params.operation = operation;
    params.planid = this.resData.planid;
    let content = operation == 'approve' ?getLabel('509442','确认批准吗？')  :getLabel('509443','确认退回吗？')  ;
    let _this = this
    confirm ({
      title: getLabel('508972','确认提示') ,
      content: content,
      onOk () {
        _this.loading = true;
        api.auditPlan (params).then (
          action (data => {
            _this.loading = false;
            if (data.api_status == '1') {
              message.success (getLabel('30700','操作成功') );
              _this.getPlanDetail ();
              

            } else {
              message.error (data.message || getLabel('383746','请求失败') );
            }
            //刷新审核列表
            if(window.opener  && typeof window.opener.planAuditRefresh === 'function'){
              window.opener.planAuditRefresh()
            }
            if(window.opener  && typeof window.opener.planGetNoAuditCount === 'function'){
              window.opener.planGetNoAuditCount()
            }
            if(doback){
              if(typeof doback=='function'){
                doback()
              }
            }
          })
        );
      },
      onCancel () {},
    });
  };

  //保存或者提交计划
  @action saveOrSubmitPlan = operation => {
    let paramsData = this.getOperationParams (operation);
    let flag = this.checkMust (paramsData);
    if (!flag) {
      message.info (getLabel('509111','请填写标题不为空的必填项！') );
      return;
    }


    this.loading = true;

    api.saveOrSubmitPlan (paramsData).then (
      action (data => {
        if (data.api_status == '1') {
          //重置计划日志查询条件
          this.planLog = {
            datas: [],
            lastcount: 0,
            lastid: '',
            status: '',
          };
          this.getPlanDetail ();
          message.success (operation == 'save' ? getLabel('22619','保存成功')  : getLabel('16248','提交成功') );
        } else {
          message.error (data.message || getLabel('383746','请求失败') );
        }
        this.loading = false;
      })
    );
  };

  //检查必填项
  checkMust = params => {
    let planlist = JSON.parse (params.planlist);
    let summaryoutlist = JSON.parse (params.summaryout);
    let summaryinlist = JSON.parse (params.summaryin);
    let planMapList = this.resData.planmap.list;
    let summaryMapList = this.resData.summarymap.list;
    var flag = true;
    if (planlist && planlist.length > 0) {
      planlist.map (v => {
        for (var k in v) {
          planMapList.map (p => {
            if (
              p['ismust'] == 1 &&
              (v[p['fieldname']] === '' || v[p['fieldname']] == undefined)
            ) {
              flag = false;
            }
          });
        }
      });
    }
    if (summaryoutlist && summaryoutlist.length > 0) {
      summaryoutlist.map (v => {
        for (var k in v) {
          summaryMapList.map (p => {
            if (p['ismust'] == 1 && !v[p['fieldname']]) {
              flag = false;
            }
          });
        }
      });
    }
    if (summaryinlist && summaryinlist.length > 0) {
      summaryinlist.map (v => {
        for (var k in v) {
          summaryMapList.map (p => {
            if (p['ismust'] == 1 && !v[p['fieldname']]) {
              
              flag = false;
            }
          });
        }
      });
    }

    return flag;
  };

  //保存报告每条计划明细详情
  @action saveDetailView = params => {
    api.saveDetailView (params).then (
      action (data => {
        if (data.api_status == '1') {
          //this.detailid = data.plandetailid;
          if (params.doback) {
            params.doback (data.plandetailid);
          }
        }
      })
    );
  };

  //delete plan detail
  @action deletePlan = () => {
    let param = {};
    param.planid = this.resData.planid;
    (param.year = this.dateSelect.year), (param.type1 = this.tabSelectKey), (param.type2 = this
      .tabSelectKey == '1'
      ? this.dateSelect.month
      : this.dateSelect.week), (param.resourceid = this.resData.resourceid);
    let _this = this
    confirm ({
      title: getLabel('508972','确认提示') ,
      content: getLabel('509113','确认删除此报告吗？') ,
      onOk () {
        api.deletePlan (param).then (
          action (data => {
            if (data.api_status == '1') {
              message.success (getLabel('30700','操作成功') );
              _this.getPlanDetail ();
            } else {
              message.error (data.message || getLabel('383746','请求失败'));
            }
          })
        );
      },
      onCancel () {},
    });
  };

  //重新编写
  @action resetPlan = () => {
    let param = {};
    param.planid = this.resData.planid;
    let _this = this
    confirm ({
      title: getLabel('508972','确认提示') ,
      content: getLabel('509114','确认重新编写吗？') ,
      onOk () {
        api.resetPlan (param).then (
          action (data => {
            if (data.api_status == '1') {
              _this.getPlanDetail ();
            } else {
              message.error (data.message || getLabel('383746','请求失败'));
            }
          })
        );
      },
      onCancel () {},
    });
  };

  //添加任务
  @action addTask = (param,record) => {
    let _ = this
    api.addTask (param).then (
      action (data => {
        if (data.api_status == '1') {
          window.open (
            '/spa/workrelate/static/index.html#/main/workrelate/task/taskDetail?id=' +
            data.taskId
            );
            let taskids = record.taskids 
            if(taskids){
              record.taskids +=  (data.taskId+',')
            }else{
              record.taskids=","+data.taskId+","
            }
            _.saveOrSubmitPlan('save')
        } else {
          message.error (data.message || getLabel('383746','请求失败') );
        }
      })
    );
  };

  @action ('获取详情数据')
  getDetailView = detailId => {
    let param = {};
    param.plandetailid = detailId;
    api.getDetailView (param).then (
      action (data => {
        if (data.api_status == '1') {
        } else {
          message.error (data.message || getLabel('383746','请求失败') );
        }
      })
    );
  };

  //去掉无用的属性
  removeFieldsNoInColumns (data) {
    if (data && data.length > 0) {
      data = data.map (v => {
        delete v['fbdate'];
        delete v['taskarray']
        delete v['filearray']
        delete v['docarray']
        delete v['wfarray']
        delete v['crmarray']
        delete v['projectarray']
        if (v.id && v.id.startsWith ('temp')) {
          delete v['id'];
        }
        return v;
      });
    }
  }

  //获取操作参数 请求参数
  getOperationParams = operation => {
    let summaryin = toJS (this.resData.summaryin);
    let summaryout = toJS (this.resData.summaryout);
    let planlist = toJS (this.resData.planlist);
    this.removeFieldsNoInColumns (summaryin);
    this.removeFieldsNoInColumns (summaryout);
    this.removeFieldsNoInColumns (planlist);
    // summaryout = this.removeNoTitleData(summaryout)
    return {
      resourceid: this.resData.resourceid,
      planid: this.resData.planid,
      operation: operation,
      planname: this.getPlanName (this.resData.resourcename),
      auditids: this.resData.auditids,
      year: this.dateSelect.year,
      type1: this.tabSelectKey,
      type2: this.tabSelectKey == '1'
        ? this.dateSelect.month
        : this.dateSelect.week,
      remark: this.inputValue.richTextValue,
      programid: this.resData.programid,
      summaryin: JSON.stringify (summaryin),
      summaryout: JSON.stringify (summaryout),
      planlist: JSON.stringify (planlist),
      fileids: this.resData.fileids,
    };
  };

  //设置工作计划标题
  getPlanName = (resourcename) => {
    //杨文元2019年28周工作总结及2019年29周工作计划
    let {year, month, week} = this.dateSelect;
    let nextYear = month == 12 ? parseInt (year) + 1 : year;
    let nextMonth = month == 12 ? 1 : (parseInt(month)+1);
    let monthOrWeekValue = this.tabSelectKey == '1' ? month + '月' : week + '周'
    let nextMonthOrWeekValue = this.tabSelectKey == '1' ? nextMonth + '月' : parseInt (week) + 1 + '周'
   
    let planname = ''
    if(getUserLanguage()=="8"){
      monthOrWeekValue = this.tabSelectKey == '1' ? "month "+month : "week "+week
      nextMonthOrWeekValue = this.tabSelectKey == '1' ? "month "+nextMonth  : "week " +  parseInt (week) + 1 
      planname = `${resourcename} ${year}-${monthOrWeekValue} work summary and ${nextYear}-${nextMonthOrWeekValue} work plan`
    }else{
      planname = `${resourcename} ${year}年${monthOrWeekValue}工作总结及${nextYear}年${nextMonthOrWeekValue}工作计划`
    }

    return planname;
  };

  //移除没有标题的数据
  removeNoTitleData (list) {
    if (!list || list.length < 1) return;
    return list.filter (v => v.name && v.name != '');
  }

  //删掉数组中的id
  removeIdFromList (list) {
    if (!list || list.length < 1) return;
    list.map ((v, i) => {
      if (v.id && v.id.length > 0) {
        list[i].id = '';
      }
    });
  }

  @action ('根据tabdatas选择tabselectkey')
  setTabSelectKeyByTabDatas () {
    const {ismonth, isweek} = this.resData;
    if (ismonth && !isweek) {
      this.tabSelectKey = '1';
    } else if (!ismonth && isweek) {
      this.tabSelectKey = '2';
    }
  }

  @action ('刷新数据')
  refreshResData (resData) {
    this.resData = resData;
  }

  //save feedback
  @action ('添加计划反馈')
  addPlanExchange = () => {
    let param = {};
    param.planid = this.resData.planid;
    param.content = this.inputValue['feedback'];
    if (!param.content || (param.content && param.content.length < 1)) {
      message.info (getLabel('383036','请输入内容') );
      return;
    }
    api.addPlanExchange (param).then (
      action (data => {
        this.inputValue.feedback = '';
        this.resData.fblist.unshift (data.datas);
      })
    );
  };


  //save share
  @action ('设置分享人')
  setPlanShare = (ids,sharedatas) => {

      this.loading = true;
      let param = {};
      param.planid = this.resData.planid;
      param.shareids = ids;
      api.setPlanShare (param).then (action (data => {
        //this.getPlanDetail ();
        this.planLog.datas.unshift(data.datas);
        this.resData.shareidsList = sharedatas;
        this.loading = false;
        })
      );
  };
}

